home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
editWindow.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
6KB
|
164 lines
<?php
/**
* Text file edition window
*
* simple text files remote editor.
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.0.0
*/
/**
* @desc display text editor
* @return void
* @param string $completeFileName complete filename of edited file
* @param string $action : action :
* "edit" : display file in editor
* "editSave" : save modified file
* "editSaveQuit" : save modified file and quit
* @param string $savedContent : content to save in file. 2 first characters indicate line break type: 23 for CRLF, or 10 for LF only, 13 for CR only
*/
function ewDisplayEditor($completeFileName, $action, $savedContent){
// Check rights
$rights=cfFileRights($completeFileName);
if(!$rights['download'] || !$rights['modify'] || !cfRGetVar('editionAllowed') || !strpos(EDITABLE_FILES,';'.cfFileExtension($completeFileName).';')) outDisplayErrorPage(cfCaption('genNoAccess'));
if($action=='editSave' || $action=='editSaveQuit'){
// Save file
$result=false;
// Set line break type
$lineBreak=substr($savedContent,0,2);
if($lineBreak==23) $lineBreak=chr(13).chr(10);
elseif($lineBreak==10 || $lineBreak==13) $lineBreak=chr($lineBreak);
else $lineBreak=10;
$savedContent=substr($savedContent,2);
if($fp=@fopen($completeFileName,'w')){
//cfDbg($savedContent);
//$savedContent=stripcslashes($savedContent);
$savedContent=str_replace('<*weezoLB*>',$lineBreak,$savedContent); // \r
//cfDbg(cfDbgTxt($savedContent,1));
$result=fwrite($fp,$savedContent);
fclose($fp);
}
// Inform user
cfAsyncHeader();
if($result===false) echo cfAsyncXMLJSaction('alert("'.cfCaptionJS('genErrorSaving').'");');
else echo cfAsyncXMLJSaction('fileSaved()');
echo cfAsyncFooter();
exit;
}
// Set close URL back to resource for frameless display
$_ENV['winCloseURL']='/res/'.cfRGetVar('type').'/'.cfRGetVar('subType').'/'.cfRGetVar('baseFile');
// Insert head and std com form
cfInsertHEAD(false);
?>
<script type="text/javascript" language="javascript">
var modified=false;
var ctrlDown=false;
function saveFile(){
var reg = new RegExp(String.fromCharCode(13)+String.fromCharCode(10)+'|'+String.fromCharCode(13)+'|'+String.fromCharCode(10), "g");
fillAndSubmit(false,'editSave',dgi('lineBreak').value+dgi("ta").value.replace(reg,'<*weezoLB*>'));
}
function fileSaved(){
dgi('save').style.display="none";
dgi('saveD').style.display="inline";
modified=false;
}
// Ctrl-S & Esc detection
function keyD(e){
if(e) kc=e.which; else {if(window.event) kc=window.event.keyCode; else return;}
if(kc==17){
ctrlDown=true;
return;
}
if(kc==27){
if(!ctrlDown && !modified) winMe.closeMe();
return;
}
if(kc==83 && ctrlDown){
if(modified) saveFile();
}
else {
if(modified==false){
dgi('saveD').style.display="none";
dgi('save').style.display="inline";
modified=true;
}
}
}
function keyU(e){
if(e) kc=e.which; else {if(W.event) kc=W.event.keyCode; else return;}
if(kc==17) ctrlDown=false;
}
</script>
<?php
if(cfGetBrowser()=='gecko'){
?>
<script type="text/javascript">
document.onkeydown=keyD;
document.onkeyup=keyU;
</script>
<?php
}
echo '<body onload="dgi(\'ta\').focus()">';
outInsertStandardComForm($_SERVER['PHP_SELF'],cfUTF8Encode(dirname($completeFileName)), cfUTF8Encode(basename($completeFileName)),false,false,false,true);
echo outDivFrame('frame1',false,'height:95%');
echo outFrameHeaderTable('frame1Header',outImage(outIcon('edit'),false,false,'margin-right:1em;').cfUTF8Encode(basename($completeFileName)),outButton(cfCaption('genSave'),'javascript:saveFile()',outIcon('save'),false,'save','style="display:none"').outButtonDisabled(cfCaption('genSave'),false,outIcon('save'),false,'saveD').' '.' ');
// Text area
echo '<textarea rows="0" cols="0" id="ta" style="position:relative;width:100%; height:95%" '.((cfGetBrowser()!='gecko')?'onkeydown="keyD()" onkeyup="keyU()"':'').'>';
if(!$fp=@fopen($completeFileName,'r')) echo cfCaption('explorerErrorView');
else {
$cr=$lf=$crlf=0;
while (!feof($fp)) {
$content=str_replace('<','<',str_replace('&','&',fread($fp, 4096)));
// Replace all line breaks by single \n
echo str_replace("\r","\n",str_replace("\r\n","\n",$content));
// count crlf to determine line break type
$content=str_replace("\r\n","",$content,$nb);
$crlf+=$nb;
// Count LF (10)
str_replace("\n","",$content,$nb);
$lf+=$nb;
// Count CR (13)
str_replace("\r","",$content,$nb);
$cr+=$nb;
//echo str_replace('&','&',str_replace("\n",chr(13),(fread($fp, 4096))));
}
fclose($fp);
if($crlf>=$cr && $crlf>=$lf) $lineBreak=23;
elseif($lf>$cr) $lineBreak=10;
else $lineBreak=13;
}
echo '</textarea>';
if(isset($lineBreak)) echo '<input style="display:none" id="lineBreak" value="'.$lineBreak.'">';
echo "</div>\n";
echo '</body></html>';
}
?>